<?php
namespace app\house\model;
use app\BaseModel;
use think\facade\Db;



class AdminCate extends BaseModel
{
    //定义表名
    protected $name = 'longbing_card_house_category';
    /**
     * @param $query
     * 查询范围
     */

    protected $append = [
        'url_text'
    ];
    public function scopeStatus($query, $status){
        $query->where('status', '>', $status);
    }
    /**
     * @param $dis
     * @return array
     * @throws \think\exception\DbException
     * 房产分类列表
     */
    public function cateList($dis,$page = 10){
        $data = $this->where($dis)->status(-1)->order('top desc')->paginate($page)->toArray();
        $data['data'] = transImages($data['data'],['img'],',');
        return $data;
    }

    /**
     * @param $value
     * @param $data
     * url
     */
    public function getUrlTextAttr($value,$data){
        $url = '/house/pages/filter/filter?id='.$data['id'].'&title='.$data['title'];
        return $url;
    }

    /**
     * @param $dis
     * @return mixed
     * 获取所有房产分类
     */
    public function cateSelect($dis){
        $data = $this->where($dis)->status(-1)->order('top desc,id desc')->select()->toArray();
        $data = transImagesOne($data,['img']);
        if(!empty($data)){
            foreach ($data as &$v){
                $v['cover'] = $v['img'];
            }
        }
        return $data;
    }
    /**
     * @param $data
     * @return int|string
     * 添加房产分类
     */
    public function cateAdd($data){
        $data['create_time'] = time();
        $data['update_time'] = time();
        $data['status']      = 1;
        $res = $this->insert($data);
        return $res;
    }


    /**
     * @param $dis
     * @param $data
     * @return AdminCate
     * 编辑房产分类
     */
    public function cateUpdate($dis,$data){
        $data['update_time'] = time();
        $res = $this->where($dis)->update($data);
        return $res;

    }


    /**
     * @param $dis
     * 房产分类详情
     */
    public function cateInfo($dis){
        $data = $this->where($dis)->status(-1)->find();
        return !empty($data)?$data->toArray():$data;
    }



}